package com.ruoyi.financial.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.base.yaml.BusinessConfig;
import com.ruoyi.bizsys.domain.FinancialManagement;
import com.ruoyi.bizsys.domain.FinancialManagementVo;
import com.ruoyi.bizsys.mapper.WalletOrderMapper;
import com.ruoyi.financial.service.FinancialManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Service
public class FinancialManagementServiceImpl implements FinancialManagementService {
    @Autowired
    private WalletOrderMapper walletOrderMapper;

    @Autowired
    BusinessConfig businessConfig;
    private static RestTemplate restTemplate;

    static {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(180000);
        factory.setReadTimeout(180000);
        restTemplate = new RestTemplate(factory);
    }

    @Override
    public List<FinancialManagement> getlist(FinancialManagementVo financialManagementvo) {
        financialManagementvo.setWalletType("1");
        financialManagementvo.setOrderType("4");
        List<FinancialManagement> financialManagements = walletOrderMapper.selectFinancial(financialManagementvo);
        for (FinancialManagement financial : financialManagements) {
            financial.setClientName(financial.getFullName());
        }
        return financialManagements;
    }

    @Override
    public void examine(JSONObject jsonObject) {
        String url = businessConfig.getApiurl() + "/financial/management";
        restTemplate.postForObject(url, jsonObject, String.class);
    }
}